package com.addzero.web.modules.demo

import com.addzero.dsl.Dsl

/**
 * 测试带有泛型参数的类
 */
@Dsl
data class Box<T>(val content: T, val label: String)

/**
 * 测试带有多个泛型参数的类
 */
@Dsl
data class Pair<K, V>(val key: K, val value: V)

/**
 * 测试带有泛型边界的类
 */
@Dsl
data class SortedBox<T : Comparable<T>>(
    val items: List<T>,
    val name: String
)

/**
 * 测试带有嵌套泛型的类
 */
@Dsl
data class NestedBox<T>(
    val boxes: List<Box<T>>,
    val description: String
)

/**
 * 测试变性（协变和逆变）
 */
@Dsl
data class Container<out T>(val items: List<T>, val size: Int)

@Dsl
data class Consumer<in T>(val processor: (T) -> String, val name: String)

/**
 * 测试泛型类的DSL构建器
 */
fun testGenericDsl() {
    // 基本泛型
    val stringBox = box<String>("dasd") {
        label = "String Box"
    }
    println("String Box: $stringBox")
    
    val intBox = box<Int>(111) {
        label="dasd"
    }
    println("Int Box: $intBox")
    
    // 多参数泛型
    val keyValuePair = pair<String, Int> ("sdasd",111){}
    println("Pair: $keyValuePair")
    
    // 泛型边界
    val sortedBox = sortedBox<Int> {
        items = listOf(3, 1, 4, 1, 5, 9)
        name = "Sorted Numbers"
    }
    println("Sorted Box: $sortedBox")
    
    // 嵌套泛型
    val nestedBox = nestedBox<String> {
        boxes = listOf(
            box<String> (""){
                label = "Box 1"
            },
            box<String>("") {
                label = "Box 2"
            }
        )
        description = "Nested boxes"
    }
    println("Nested Box: $nestedBox")
    
    // 变性测试
    val stringContainer = container<String> {
        items = listOf("one", "two", "three")
        size = 3
    }
    println("Container: $stringContainer")
    
    val stringConsumer = consumer<String> {
        processor = { it.uppercase() }
        name = "String Upper Case"
    }
    println("Consumer result: ${stringConsumer.processor("test")}")
}